from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QSize
class daduojiaoBone(QDialog):
    age_male = [23,31,46,66,83,95,108,117]
    age_female = [20,27,42,60,80,95,111,119]

    boneName = "大多角骨"
    #全局设定骨头的年龄
    globals()["this_bone_age"] = 0
    lbl = QLabel
    #创建类的初始化方法，定义一些默认的参数
    def __init__(self, text='',gender=''):
        super().__init__()
        self.name = text
        #根据性别来判断数据
        if gender == '0':
            self.age = self.age_female
        else:
            self.age = self.age_male
        self.initUI()

    #视图初始化 主要加载loadImage方法
    def initUI(self):
        #导入图片
        self.loadImage('daduojiao',0,8)

    #视图所在
    def loadImage(self,name,number_begin,number_end):
        #self.buttons = QButtonGroup()
        btn = []

        vLayout = QVBoxLayout()    #垂直布局
        hLayout0 = QHBoxLayout()  #标签行行
        hLayout1 = QHBoxLayout()  #第一行
        hLayout2 = QHBoxLayout()  #第二行
        hLayout3 = QHBoxLayout()  #第三行按钮

        nullBtn = QPushButton()
        null_btnIcon = QIcon()
        nullpixmap = QPixmap()
        null_image_dir =  "./images/null.jpg"
        nullpixmap.load(null_image_dir)
        null_btnIcon.addPixmap(nullpixmap)
        size = QSize(110,110)
        nullBtn.setIconSize(size)
        nullBtn.setIcon(null_btnIcon)
        #加入信号槽
        btn.append(nullBtn)
        #self.buttons.addButton(nullBtn,0)
        hLayout1.addWidget(nullBtn)
        nullBtn.clicked.connect(self.printvalTESTnull)

        for i in range(0,3):
            newBtn = QPushButton()
            #btn[i] = QPushButton()
            btnIcon = QIcon()
            pixmap = QPixmap()
            image_dir =  "./images/"+name+"_"+ str(i)+".jpg"
            pixmap.load(image_dir)
            btnIcon.addPixmap(pixmap)
            size = QSize(110,110)
            newBtn.setIconSize(size)
            newBtn.setIcon(btnIcon)
            newBtn.isCheckable()
            #加入信号槽
            btn.append(newBtn)
            #self.buttons.addButton(newBtn,self.age[i])
            hLayout1.addWidget(newBtn)

            if i == 0:
                newBtn.clicked.connect(self.printvalTEST0)
            elif i == 1:
                newBtn.clicked.connect(self.printvalTEST1)
            elif i == 2:
                newBtn.clicked.connect(self.printvalTEST2)
            elif i == 3:
                newBtn.clicked.connect(self.printvalTEST3)

        for i in range(4,number_end):
            newBtn = QPushButton()
            #btn[i] = QPushButton()
            btnIcon = QIcon()
            pixmap = QPixmap()
            image_dir =  "./images/"+name+"_"+ str(i)+".jpg"
            pixmap.load(image_dir)
            btnIcon.addPixmap(pixmap)
            size = QSize(110,110)
            newBtn.setIconSize(size)
            newBtn.setIcon(btnIcon)
            newBtn.isCheckable()
            #加入信号槽
            btn.append(newBtn)
            #self.buttons.addButton(newBtn,self.age[i])
            hLayout2.addWidget(newBtn)

            if i == 4:
                newBtn.clicked.connect(self.printvalTEST4)
            elif i == 5:
                newBtn.clicked.connect(self.printvalTEST5)
            elif i == 6:
                newBtn.clicked.connect(self.printvalTEST6)
            elif i == 7:
                newBtn.clicked.connect(self.printvalTEST7)
#设定标题
        self.lbl = QLabel(self.boneName, self)
        style = QFont('SansSerif', 24,600)
        #style.setStyle()
        self.lbl.setFont(style)
        self.lbl.move(200, 400)
        hLayout0.addWidget(self.lbl)

        lbl2 = QLabel('', self)
        hLayout3.addWidget(lbl2)

        vLayout.addLayout(hLayout0)
        vLayout.addLayout(hLayout1)
        vLayout.addLayout(hLayout2)
        vLayout.addLayout(hLayout3)


        self.setLayout(vLayout)
        #self.move(-260,0)
    def printvalTESTnull(self):
        self.printval(-1)

    def printvalTEST0(self):
        self.printval(0)

    def printvalTEST1(self):
        self.printval(1)
    def printvalTEST2(self):
        self.printval(2)
    def printvalTEST3(self):
        self.printval(3)
    def printvalTEST4(self):
        self.printval(4)
    def printvalTEST5(self):
        self.printval(5)
    def printvalTEST6(self):
        self.printval(6)
    def printvalTEST7(self):
        self.printval(7)

    def printval(self,text):

        if text >= 0:
            self.this_bone_age = self.age[text]
        else:
            self.this_bone_age = 0
        self.lbl.setText(self.boneName + ": " + str(self.this_bone_age))

        #print(self.this_bone_age)
        from sqlite import insert
        insert(self.name,self.this_bone_age,'DADUOJIAO','num')
